package com.haust.dianqi.service.impl;

import com.haust.dianqi.mapper.UserFileMapper;
import com.haust.dianqi.pojo.UserFile;
import com.haust.dianqi.service.UserFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * @Auther: csp1999
 * @Date: 2020/04/27/10:33
 * @Description:
 */
@Service
@Transactional
public class UserFileServiceImpl implements UserFileService {

    @Autowired
    private UserFileMapper userFileMapper;

    @Override
    public List<UserFile> findByUserId(String id) {
        return userFileMapper.findByUserId(id);
    }

    @Override
    public void save(UserFile userFile) {
        //是否是图片 解决方案：当类型中含有image时说明一定是图片类型
        boolean isImage = userFile.getType().startsWith("image");//判断是否是以 image开头的字符串
        if(isImage){
            userFile.setIsimg("是");
        }else{
            userFile.setIsimg("否");
        }
        userFile.setDowncounts(0);
        userFile.setUploadTime(new Date());
        userFileMapper.save(userFile);
    }

    @Override
    public UserFile findById(String id) {
        return userFileMapper.findById(id);
    }

    @Override
    public void update(UserFile userFile) {
        userFileMapper.update(userFile);
    }

    @Override
    public void delete(String id) {
        userFileMapper.delete(id);
    }
}
